/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package core.threads.server;

import models.*;
import models.Card.*;
import models.Skill.*;

/**
 * 处理判定的线程
 * @author Invince
 */
public class 舍弃版本_Judge_Card implements Runnable {

    protected Card judgeCard;
    protected boolean isFirstResponse;//初始为true，注意不是静态的，而是每次run初始都为true,不为true时，只能出无懈可击作为response
                                      //应该在控制出牌里做的~~~

    public synchronized void run() {
        this.isFirstResponse=true;//初始为true，注意不是静态的，而是每次run初始都为true,不为true时，只能出无懈可击作为response
        boolean doIt=true;

        /*?????????????验证下面代码的逻辑*/
        Long tBegin=System.currentTimeMillis();
        Long tEnd=System.currentTimeMillis();
        while((tEnd-tBegin)<15*1000){//15*1000 ms
            Server_Public_Data.MessageCast mResponse=Server_Public_Data.responseQueue.poll();//poll returns null if not obtain
            if(mResponse!=null){//means there si a response
                Player tempPlayer=Server_Public_Data.game.getListPlayer().get(mResponse.getSourcePlayerID());
                Card responseCard=tempPlayer.getDeckPlayer().get(mResponse.getCardID());
                Skill responseSkill=responseCard.getListSkill().get(mResponse.getSpellID());
                doIt&=handleResult(responseCard, responseSkill);
                tBegin=System.currentTimeMillis();
                Server_Public_Data.refreshScreen();//刷新屏幕，显示谁出了什么牌。。。
            }
            tEnd=System.currentTimeMillis();
        }
    }

        /**
     * 处理回应牌
     * @param castCard
     * @param castSkill
     * @param responseCard
     * @param responseSkill
     * @return
     */
    public boolean handleResult(Card responseCard,Skill responseSkill){
        if(responseCard.getName().equals("无懈可击")){
            //把出过的牌扔到弃牌堆是否在这里？？？？？？？？？？
            return false;
        }
        if(responseCard.getName().equals("过河拆桥")){
            //把出过的牌扔到弃牌堆是否在这里？？？？？？？？？？
            return false;
        }
        return true;
    }

}
